package pers.litao.bit.product.service.impl;


import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.jsonwebtoken.Claims;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pers.litao.bit.commons.entities.priduct.DetailedEntity;
import pers.litao.bit.commons.entities.priduct.GoodsEntity;

import pers.litao.bit.commons.entities.priduct.PictureEntity;
import pers.litao.bit.commons.entities.priduct.UnitEntity;
import pers.litao.bit.commons.entities.user.AddressEntity;
import pers.litao.bit.commons.entities.user.UserInfoEntity;
import pers.litao.bit.commons.utils.*;
import pers.litao.bit.commons.vo.product.GoodsVo;

import pers.litao.bit.commons.vo.product.PageGoodsVo;
import pers.litao.bit.commons.vo.product.UserGoodsListVo;
import pers.litao.bit.product.dao.GoodsMapper;
import pers.litao.bit.product.openfeign.UserFeignService;
import pers.litao.bit.product.service.DetailedService;
import pers.litao.bit.product.service.GoodsService;
import pers.litao.bit.product.service.UnitService;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 李涛
 * @date 2020-11-25 14:47
 */
@Service
@Slf4j
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, GoodsEntity> implements GoodsService {
    @Resource
    private DetailedService detailedService;

    @Resource
    private UserFeignService userFeignService;

    @Resource
    private  UnitService unitService;
    /**
     * 保存商品
     *
     * @param goodsEntity
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R saveGoods(GoodsEntity goodsEntity, LoginUserInfo loginUserInfo) {
        DetailedEntity detailedEntity = new DetailedEntity();
        if(null == goodsEntity){
            log.error("商品为空" +SysUtil.getClientInfo().buildInfo());
            return R.error(Constant.ResponseCode.SUBMIT_DATA_ILLEGALITY.getCode(),
                    Constant.ResponseCode.SUBMIT_DATA_ILLEGALITY.getMsg(),null);
        }
        // 商品详情保存在另外的表
        detailedEntity.setContent(goodsEntity.getDetailed());
        detailedService.getBaseMapper().insert(detailedEntity);
        Long createTime =  System.currentTimeMillis();
        // 零售商不能发布商品
        if(loginUserInfo.getIdentity() == 0){
            log.error("身份验证错误"+loginUserInfo.info() + SysUtil.getClientInfo().buildInfo());
            return R.error(Constant.ResponseCode.RETAIL_NOT_RELEASE_GODDS.getCode(),
                    Constant.ResponseCode.RETAIL_NOT_RELEASE_GODDS.getMsg(),null);
        }
        goodsEntity.setUserId(loginUserInfo.getUserId());
        goodsEntity.setCreateTime(createTime);
        goodsEntity.setMDate(goodsEntity.getReceiveMDate());
        goodsEntity.setQDate(goodsEntity.getReceiveQDate());
        //生成库存量和浏览量随机数
        // goodsEntity.setInventory(NumberUtil.generateBySet(1000, 10000, 1)[0]);
        // goodsEntity.setPageViews(NumberUtil.generateBySet(1000, 10000, 1)[0]);
        goodsEntity.setDetailedId(detailedEntity.getId());
        this.save(goodsEntity);
        log.info("商品保存成功" +loginUserInfo.info()+SysUtil.getClientInfo().buildInfo());
        return R.ok();
    }

    /**
     * 根据商品IDS获取商品列表
     *
     * @param ids
     * @return
     */
    @Override
    public R getGoodsListByIds(Long[] ids) {
        if(ids == null || ids.length == 0){
            log.error("商品IDS为空" +SysUtil.getClientInfo().buildInfo());
            return R.ok(new ArrayList<>());
        }
        List<GoodsVo> collect = this.listByIds(Arrays.asList(ids)).stream()
                .map(m -> {
                    GoodsVo goodsVo = new GoodsVo();
                    goodsVo.setId(m.getId())
                            .setPictures(JSONUtil.parseArray(m.getPicture()).toList(PictureEntity.class))
                            .setGoodsName(m.getGoodsName())
                            .setLabelId(m.getLabelId());

                    return goodsVo;
                }).collect(Collectors.toList());
        log.info("用户请求成功" + SysUtil.getClientInfo().buildInfo());
        return R.ok(collect);
    }

    /**
     * 获取商品数量
     *
     * @param loginUserInfo
     * @return
     */
    @Override
    public R getGoodsCount(LoginUserInfo loginUserInfo) {
        QueryWrapper<GoodsEntity> queryWrapper = new QueryWrapper<>();
        // 登录时根据地址查询
        if(null != loginUserInfo){
            R r = userFeignService.getUserIds(loginUserInfo.getUserId());
            List<Long> userIds = JSONUtil.parseArray(r.get("data")).toList(Long.class);
            // 该地方存在商品且大于4个
            if(userIds.size() > 0){
                queryWrapper.in("user_id",userIds);
            }
        }
        log.info("用户请求成功" + SysUtil.getClientInfo().buildInfo());
        return R.ok(this.count(queryWrapper));
     //   return null;
    }

    /**
     * 根据id查询商品
     *
     * @param id 商品id
     * @return r
     */
    @Override
    public R getGoodsById(Long id) {
        // 查询商品
        GoodsEntity goodsEntity = this.baseMapper.selectById(id);
        // 获取用户信息
        R r = userFeignService.getUser(goodsEntity.getUserId());
        // 查询详情
        DetailedEntity detailedEntity = detailedService.getBaseMapper().selectById(goodsEntity.getDetailedId());
        // 查询单位
        UnitEntity unitEntity = unitService.getBaseMapper().selectById(goodsEntity.getUnitId());

        JSONArray objects = JSONUtil.parseArray(goodsEntity.getPicture());
        List<PictureEntity> pictureEntities = objects.toList(PictureEntity.class);
        GoodsVo goodsVo = new GoodsVo();
        JSON parse = JSONUtil.parse(r);
        UserInfoEntity byPathUser = parse.getByPath("data.userData", UserInfoEntity.class);
        AddressEntity byPathAddress = parse.getByPath("data.addressData", AddressEntity.class);
        //封装返回对象
        goodsVo.setId(goodsEntity.getId())
                .setUserId(byPathUser.getId())
                .setUserName(byPathUser.getName())
                .setIsCcd(goodsEntity.getIsCcd() == 1)
                .setIsDaysend(goodsEntity.getIsDaysend() == 1)
                .setIsAfp(goodsEntity.getIsAfp() == 1)
                .setPictures(pictureEntities)
                .setGoodsName(goodsEntity.getGoodsName())
                .setPrice(goodsEntity.getPrice())
                .setStoreName(byPathUser.getStoreName())
                .setAddress(byPathAddress.getUserInputAddress())
                .setPageViews(goodsEntity.getPageViews())
                .setInventory(goodsEntity.getInventory())
                .setDetailed(detailedEntity.getContent())
                .setPhone(byPathUser.getPhone())
                .setUnit(unitEntity.getUnitName())
                .setRetailPrice(goodsEntity.getRetailPrice());
        log.info("查询ID为" +id+"商品成功" +SysUtil.getClientInfo().buildInfo());
        return R.ok(goodsVo);
    }



    /**
     * 获取最热商品
     *
     * @return r
     */
    @Override
    public R getHotGoods( LoginUserInfo loginUserInfo) {
        QueryWrapper<GoodsEntity> queryWrapper = new QueryWrapper<>();
        // 登录时根据地址查询
        if(null != loginUserInfo){
            R r = userFeignService.getUserIds(loginUserInfo.getUserId());
            List<Long> userIds = JSONUtil.parseArray(r.get("data")).toList(Long.class);
            // 该地方存在商品且大于4个
            if(userIds.size() > 0){
                queryWrapper.in("user_id",userIds);
            }
            else {
                queryWrapper.eq("id", -1);
            }
        }
        Page<GoodsEntity> page = new Page<>();
        page.setCurrent(1);
        page.setSize(Constant.HOT_SIZE);
        this.baseMapper.selectPage(page, queryWrapper
                .orderByDesc("page_views"));
        List<GoodsEntity> records = page.getRecords();
        List<PageGoodsVo> collect = records.stream()
                .map(g -> {
                    PageGoodsVo pageGoodsVo = new PageGoodsVo();
                    pageGoodsVo.setGoodsName(g.getGoodsName());
                    pageGoodsVo.setId(g.getId());
                    pageGoodsVo.setPrice(g.getPrice());
                    List<PictureEntity> pictureEntityList = JSONUtil.parseArray(g.getPicture()).toList(PictureEntity.class);
                    pageGoodsVo.setPicture(pictureEntityList.get(0).getUrl());
                    return pageGoodsVo;
                })
                .collect(Collectors.toList());
        log.info("用户请求成功" + SysUtil.getClientInfo().buildInfo());
        return R.ok(collect);
    }

    /**
     * 获取最新商品
     *
     * @return r
     */
    @Override
    public R getNewGoods(LoginUserInfo loginUserInfo) {
        QueryWrapper<GoodsEntity> queryWrapper = new QueryWrapper<>();
        // 登录时根据地址查询
        if(null != loginUserInfo){
            R r = userFeignService.getUserIds(loginUserInfo.getUserId());
            List<Long> userIds = JSONUtil.parseArray(r.get("data")).toList(Long.class);
            // 该地方存在商品
            if(userIds.size() > 0){
                queryWrapper.in("user_id",userIds);
            }
            else {
                queryWrapper.eq("id", -1);
            }
        }
        Page<GoodsEntity> page = new Page<>();
        page.setCurrent(1);
        page.setSize(Constant.NEW_SIZE);
        this.baseMapper.selectPage(page, queryWrapper
                .orderByDesc("inventory"));
        List<PageGoodsVo> collect = page.getRecords().stream()
                .map(g -> {
                    PageGoodsVo pageGoodsVo = new PageGoodsVo();
                    pageGoodsVo.setGoodsName(g.getGoodsName());
                    pageGoodsVo.setId(g.getId());
                    pageGoodsVo.setPrice(g.getPrice());
                    List<PictureEntity> pictureEntityList = JSONUtil.parseArray(g.getPicture()).toList(PictureEntity.class);
                    pageGoodsVo.setPicture(pictureEntityList.get(0).getUrl());
                    return pageGoodsVo;
                })
                .collect(Collectors.toList());
        log.info("用户请求成功" + SysUtil.getClientInfo().buildInfo());
        return R.ok(collect);
    }

    /**
     * 获取商品列表
     *
     * @return r
     */
    @Override
    public R getGoodsList(Map<String,Object> params,LoginUserInfo loginUserInfo) {
        QueryWrapper<GoodsEntity> queryWrapper = new QueryWrapper<>();
        // 登录时根据地址查询
        if(null != loginUserInfo){
            R r = userFeignService.getUserIds(loginUserInfo.getUserId());
            List<Long> userIds = JSONUtil.parseArray(r.get("data")).toList(Long.class);
            if(userIds.size() > 0){
                queryWrapper.in("user_id",userIds);
            }
        }
        Page<GoodsEntity> page = new Page<>();
        page.setCurrent(Long.parseLong((String) params.get("page")));
        page.setSize(Constant.SIZE); //一页查8个
   //     QueryWrapper<GoodsEntity> queryWrapper = new QueryWrapper<>();
        if(params.containsKey("labelIds")){
            String labelIds = (String) params.get("labelIds");
            if (StrUtil.isNotBlank(labelIds)){
                queryWrapper.in("label_id", Arrays.asList(labelIds.split(";").clone()));
            }
        }
        if(params.containsKey("keyWord")){
            String keyWord = (String) params.get("keyWord");
            if(StrUtil.isNotBlank(keyWord)){
                queryWrapper.like("goods_name", keyWord);
            }
        }
        this.baseMapper.selectPage(page, queryWrapper);
        //List<GoodsEntity> records = page.getRecords();
        List<PageGoodsVo> collect = page.getRecords().stream()
                .map(g -> {
                    PageGoodsVo pageGoodsVo = new PageGoodsVo();
                    pageGoodsVo.setGoodsName(g.getGoodsName());
                    pageGoodsVo.setId(g.getId());
                    pageGoodsVo.setPrice(g.getPrice());
                    List<PictureEntity> pictureEntityList = JSONUtil.parseArray(g.getPicture()).toList(PictureEntity.class);
                    pageGoodsVo.setPicture(pictureEntityList.get(0).getUrl());
                    return pageGoodsVo;
                })
                .collect(Collectors.toList());
        Map<String,Object> map = new HashMap<>();
        map.put("goodsList", collect);
        map.put("size",page.getTotal());
        log.info("用户请求成功" + SysUtil.getClientInfo().buildInfo());
        return R.ok(map);
    }

    /**
     * 获取个人用户第几页商品
     *
     * @return r
     */
    @Override
    public R userGoodsList(Long current,LoginUserInfo loginUserInfo) {
        // 分页查询
        Page<GoodsEntity> page = new Page<>();
        page.setCurrent(current);
        //一页查8个
        page.setSize(Constant.USER_LIST_SIZE);
        this.baseMapper.selectPage(page, new QueryWrapper<GoodsEntity>()
                .eq("user_id", loginUserInfo.getUserId()));
        List<UserGoodsListVo> collect = page.getRecords().stream()
                .map(g -> {
                    UserGoodsListVo userGoodsListVo = new UserGoodsListVo();
                    BeanUtils.copyProperties(g, userGoodsListVo);
                    List<PictureEntity> pictureEntityList = JSONUtil.parseArray(userGoodsListVo.getPicture()).toList(PictureEntity.class);
                    String picture = pictureEntityList.get(0).getUrl();
                    userGoodsListVo.setPicture(picture);
                    return userGoodsListVo;
                })
                .collect(Collectors.toList());
        Map<String,Object> map = new HashMap<>();
        map.put("goodsList", collect);
        map.put("size",page.getTotal());
        log.info("用户请求成功" + SysUtil.getClientInfo().buildInfo());
        return R.ok(map);
    }

    /**
     * 根据商品id删除商品
     *
     * @param id 商品id
     * @return R
     */
    @Override
    public R deleteById(Long id, LoginUserInfo loginUserInfo) {
        GoodsEntity goodsEntity = this.baseMapper.selectById(id);
        if(!goodsEntity.getUserId().equals(loginUserInfo.getUserId())){
            log.error("身份验证错误"+loginUserInfo.info() + SysUtil.getClientInfo().buildInfo());
            return R.error(Constant.ResponseCode.NO_PERMISSION.getCode(),
                    Constant.ResponseCode.NO_PERMISSION.getMsg(), null);
        }
        log.info("用户删除ID为"+id+"的商品成功" + loginUserInfo.info() + SysUtil.getClientInfo().buildInfo());
        this.baseMapper.deleteById(id);
        return R.ok();
    }

    /**
     * 商品详细处的猜你喜欢
     *
     * @param id 商品id
     * @return r
     */
    @Override
    public R detailedGuessYouLike(Long id, LoginUserInfo loginUserInfo) {
        GoodsEntity goodsEntity = this.baseMapper.selectById(id);
        Page<GoodsEntity> goodsEntityPage = new Page<>();
        goodsEntityPage.setCurrent(1L);
        goodsEntityPage.setSize(Constant.DETAILED_RECOMMENDED_SIZE);
        this.baseMapper.selectPage(goodsEntityPage, new QueryWrapper<GoodsEntity>()
                .eq("label_id", goodsEntity.getLabelId())
                .orderByDesc("page_views"));
        List<PageGoodsVo> collect = goodsEntityPage.getRecords().stream()
                .map(g -> {
                    PageGoodsVo pageGoodsVo = new PageGoodsVo();
                    pageGoodsVo.setGoodsName(g.getGoodsName());
                    pageGoodsVo.setId(g.getId());
                    pageGoodsVo.setPrice(g.getPrice());
                    List<PictureEntity> pictureEntityList = JSONUtil.parseArray(g.getPicture()).toList(PictureEntity.class);
                    pageGoodsVo.setPicture(pictureEntityList.get(0).getUrl());
                    return pageGoodsVo;
                })
                .collect(Collectors.toList());
        log.info("用户请求成功" + SysUtil.getClientInfo().buildInfo());
        return R.ok(collect);
    }

    /**
     * 爬取商品
     *
     * @param key
     * @return
     */
    @Override
    public R getTmallGoods(String key) {
//        Thread thread = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                    saveMoreGoods(key);
//            }
//        });
//        thread.start();
        return R.ok();
    }

    /**
     * 爬虫爬取天猫商品
     *
     * @param key
     */
    public void saveMoreGoods(String key) {
        try {
            int[] arr = new int[]{0};
            List<GoodsEntity> tmall = getTmall(key,arr);
            System.out.println(arr[0]);
            System.out.println(tmall.size());
            if(arr[0] == 0 || tmall.size() >=50){
                int index = 1;
                for (GoodsEntity goodsEntity : tmall) {
                    goodsEntity.setUnitId(4L)
                            .setIsCcd(0)
                            .setIsAfp(1)
                            .setIsDaysend(1)
                            .setLabelId(2L);
                    saveGoods(goodsEntity,new LoginUserInfo());
                    System.out.println("保存第" +index+ "件商品成功");
                    index++;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public List<GoodsEntity> getTmall(String key,int[] arr) throws IOException {
        List<GoodsEntity> goodsEntities = new ArrayList<>();
        System.out.println("开始爬取" +key + ".....");
        System.out.println("-------------------------------");
// 需要爬取商品信息的网站地址
        String url = "https://list.tmall.com/search_product.htm?q=" + key;
// 动态模拟请求数据
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(url);
// 模拟浏览器浏览（user-agent的值可以通过浏览器浏览，查看发出请求的头文件获取）
        httpGet.setHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36");
        CloseableHttpResponse response = httpclient.execute(httpGet);
// 获取响应状态码
        int statusCode = response.getStatusLine().getStatusCode();
        try {
            HttpEntity entity = response.getEntity();
            // 如果状态响应码为200，则获取html实体内容或者json文件
            if(statusCode == 200){
                String html = EntityUtils.toString(entity, Consts.UTF_8);
                // 提取HTML得到商品信息结果
                Document doc = null;
                // doc获取整个页面的所有数据
                doc = Jsoup.parse(html);
                //输出doc可以看到所获取到的页面源代码
                //System.out.println(doc);
                // 通过浏览器查看商品页面的源代码，找到信息所在的div标签，再对其进行一步一步地解析
                Elements ulList = doc.select("div[class='view grid-nosku']");
                Elements liList = ulList.select("div[class='product']");
                int index = 1;
                // 循环liList的数据（具体获取的数据值还得看doc的页面源代码来获取，可能稍有变动）
                for (Element item : liList) {
                    System.out.println("正在获取第" + index + "个商品........");
                    // 商品ID
//                    String id = item.select("div[class='product']").select("p[class='productStatus']").select("span[class='ww-light ww-small m_wangwang J_WangWang']").attr("data-item");
//                    System.out.println("商品ID："+id);
//                    // 商品名称
//                    String name = item.select("p[class='productTitle']").select("a").attr("title");
//                    System.out.println("商品名称："+name);
                    // 商品价格
                    String price = item.select("p[class='productPrice']").select("em").attr("title");
                //    System.out.println("商品价格："+price);
                    // 商品网址
                    String goodsUrl = item.select("p[class='productTitle']").select("a").attr("href");
                   // System.out.println("商品网址："+goodsUrl);
                    // 商品图片网址
                    String imgUrl = item.select("div[class='productImg-wrap']").select("a").select("img").attr("data-ks-lazyload");
//                    System.out.println("商品图片网址："+imgUrl);
//                    System.out.println("----------------爬取商品详细信息---------------");
                    GoodsEntity goodsEntity = getTmallGoodsDetailed("https:" +goodsUrl, arr);
                    if(goodsEntity != null){
                        goodsEntity.setPrice(BigDecimal.valueOf(Double.parseDouble(price)));
                        goodsEntities.add(goodsEntity);
                    }
                    System.out.println("获取第" + index + "个商品完成........");
                    System.out.println("-----------------------------");
                    index++;
                }

                // 消耗掉实体
                EntityUtils.consume(response.getEntity());
                System.out.println("----------------所有商品获取完成----------------------");
            } else {
                // 消耗掉实体
                EntityUtils.consume(response.getEntity());
            }
        } catch (IOException e) {
            arr[0] = 1;
            e.printStackTrace();
        } finally {
            response.close();
        }
        return goodsEntities;
    }
    public GoodsEntity getTmallGoodsDetailed(String myUrl,int[] arr) throws IOException {
        System.out.println("开始爬取商品细节......");
        GoodsEntity goodsEntity = new GoodsEntity();
// 需要爬取商品信息的网站地址
// 动态模拟请求数据
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(myUrl);
// 模拟浏览器浏览（user-agent的值可以通过浏览器浏览，查看发出请求的头文件获取）
        httpGet.setHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36");

        CloseableHttpResponse response = httpclient.execute(httpGet);
// 获取响应状态码
        int statusCode = response.getStatusLine().getStatusCode();
        try {
            HttpEntity entity = response.getEntity();
            // 如果状态响应码为200，则获取html实体内容或者json文件
            if(statusCode == 200){
                List<PictureEntity> pictureEntityList = new ArrayList<>();
                String html = EntityUtils.toString(entity, Consts.UTF_8);
                Document doc = null;
                doc = Jsoup.parse(html);
                Elements ulList = doc.select("div[class='tb-thumb-warp']");
                Elements liList = ulList.select("li");
                int lii = 0;
                for (Element item : liList) {
                    PictureEntity pictureEntity = new PictureEntity();
                    String goodsImg = item.select("li").select("img").attr("src");
                    pictureEntity.setUrl("https:" +StrUtil.replace( goodsImg, "60x60","800x800"));
                    Snowflake snowflake = IdUtil.getSnowflake(lii, lii);
                    long id = snowflake.nextId();
                    pictureEntity.setUid(id);
                    pictureEntity.setName(goodsImg);
                    pictureEntity.setStatus("success");
                    pictureEntityList.add(pictureEntity);
                }
                Elements h1 = doc.select("h1");
                for(Element e : h1){
                    String attr = e.select("h1").attr("data-spm");
                    String goodsName = e.select("h1[data-spm='" +attr +"']").text();
                    if(goodsName.length() > 0){
                        goodsEntity.setGoodsName(goodsName);
                    }
                }
                if(pictureEntityList.size() > 4){
                    StringBuilder str = new StringBuilder();
                    for(int i = 4;i < pictureEntityList.size();i++){
                        str.append("<p><img src=\"").append(pictureEntityList.get(i).getUrl()).append("\" style=\"max-width:100%;\"><br></p>");
                    }
                    goodsEntity.setDetailed(str.toString());
                }
                else {
                    goodsEntity.setDetailed("<p><img src=\"" +pictureEntityList.get(pictureEntityList.size() - 1).getUrl() +"\" style=\"max-width:100%;\"><br></p>");
                }
                JSON parse = JSONUtil.parse(pictureEntityList);
                goodsEntity.setPicture(parse.toString());
                // 消耗掉实体
                EntityUtils.consume(response.getEntity());
            } else {
                // 消耗掉实体
                EntityUtils.consume(response.getEntity());
            }
        } catch (IOException e) {
            arr[0] = 1;
            e.printStackTrace();
        } finally {
            response.close();
        }
        return goodsEntity;
    }
}
